package woshiheima6;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

//List集合

public class ListDemo {

    public static void main(String[] args) {
        //创建list集合
        List<Student> list = new ArrayList<Student>();
        //创建学生对象

        Student s1 = new Student();
        s1.setName("林青霞");
        s1.setAge(18);

        Student s2 = new Student();
        s2.setName("林青");
        s2.setAge(18);

        Student s3 = new Student();
        s3.setName("林");
        s3.setAge(18);
        //将对象传给list集合
        list.add(s1);
        list.add(s2);
        list.add(s3);
        //for循环遍历数组
       /*  for (int i =0;i<list.size();i++){
             Student s= list.get(i);
             System.out.println(s.getName()+","+s.getAge());*/
        //list迭代器循环遍历
        ListIterator<Student> lis=list.listIterator();
        while (lis.hasNext()){
            Student st=lis.next();

            if (st.equals("林青")){
                Student s4 = new Student();
                s3.setName("林er");
                s3.setAge(18);
                list.add(s4);
            }
            System.out.println(st.getName()+","+st.getAge());
        }
    }}

